package com.iwhalecloud.citybrain.flow.platform.manager.application.service.impl;

import com.iwhalecloud.citybrain.flow.platform.manager.application.service.FlowCandidateServiceAdapter;
import com.iwhalecloud.citybrain.flow.platform.manager.application.service.UserCustomFunctionService;
import com.iwhalecloud.citybrain.flow.platform.manager.domain.model.CustomFunctionVo;
import com.iwhalecloud.citybrain.flow.platform.manager.domain.repository.FlowUserTaskCustomExpressionRepository;
import org.flowable.engine.RuntimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class UserCustomFunctionServiceImpl implements UserCustomFunctionService {

    @Autowired
    private FlowUserTaskCustomExpressionRepository flowUserTaskCustomExpressionRepository;

        @Autowired
    private FlowCandidateServiceAdapter flowCandidateServiceAdapter;
    @Autowired
    private RuntimeService runtimeService;

    @Override
    public List<CustomFunctionVo> getCustomFunctionByFunId(String funId, String processInstanceId, String userCode) {
//        // 获取拟稿人
        String ngrUser = flowCandidateServiceAdapter.getNgrUser(processInstanceId, userCode);
//        return flowUserTaskCustomExpressionRepository.getCustomFunctionByFunId(funId, ngrUser, userCode);

        // 获取流程变量
        Map<String,Object> variables = runtimeService.getVariables(processInstanceId);
        return flowUserTaskCustomExpressionRepository.getCustomFunctionByFunId(funId,ngrUser,userCode,variables);

    }

}
